export function getRandomNum(min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

export const filterEffectObj = (targetObj, checkEffect) => {
  const resultObj = {};
  const keys = Object.keys(targetObj);
  keys.forEach((key) => {
    if (checkEffect(targetObj[key])) {
      resultObj[key] = targetObj[key];
    }
  });
  return resultObj;
};

// date转yyyy-MM-dd hh:mm:ss格式或yyyy-MM-dd格式
export function formatDate(date, format) {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  const hour = String(date.getHours()).padStart(2, "0");
  const minute = String(date.getMinutes()).padStart(2, "0");
  const second = String(date.getSeconds()).padStart(2, "0");
  if (format === "yyyy-MM-dd hh:mm:ss") {
    return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
  } else {
    return `${year}-${month}-${day}`;
  }
}


// 获取当前Date和对应的年月日，以及7天前的Date和对应的年月日
export function getDateAnd7DaysAgo() {
  const today = new Date();
  const year = today.getFullYear();
  const month = String(today.getMonth() + 1).padStart(2, "0");
  const day = String(today.getDate()).padStart(2, "0");
  const sevenDaysAgo = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);
  const sevenYear = sevenDaysAgo.getFullYear();
  const sevenMonth = String(sevenDaysAgo.getMonth() + 1).padStart(2, "0");
  const sevenDay = String(sevenDaysAgo.getDate()).padStart(2, "0");
  return {
    today: {
      date: today,
      dateStr: `${year}-${month}-${day}`,
    },
    sevenDaysAgo:{
      date: sevenDaysAgo,
      dateStr: `${sevenYear}-${sevenMonth}-${sevenDay}`,
    },
  };
}

const LEVEL_MAP = {
  1: "一星",
  2: "二星",
  3: "三星",
  4: "四星",
  5: "五星",
}
// 星级转换
export function levelTransform(level) {
  return LEVEL_MAP[level] || "未知星级";
}